<?php

namespace App\Http\Middleware;

use Closure;

class RemovePrefix
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $uri = $_SERVER['REQUEST_URI'];
        $public_view = env("PUBLIC_PREFIX","public");
        $download_view = env("DOWNLOAD_PREFIX","download");
        $uri = preg_replace("/^\/$public_view|^\/$download_view|\/+$/",'',$uri);
        $request->attributes->set("uri",$uri);
        return $next($request);
    }
}
